<?php
/**
 * RedCross Application
 *
 */

/**
 * Course Service class for communication between controllers and persistent storage
 */
class Core_Service_Access extends RedCross_Service_ServiceAbstract
{
        private $_memberService;

    /**
     * Constructor
     * @param Core_Gateway_User $gateway
     */
    public function __construct(Core_Gateway_Access $gateway)
    {
        parent::__construct($gateway, 'Core_Model_Access');
    }

    public function fetchAllAccess($paginate = false)
    {
        $this->checkAcl('fetch');
        return $this->_gateway->fetchAllAccess($paginate);
    }

    public function create(array $data)
    {
        $this->checkAcl('create');
        $new_area = $data['area'];
        $area = new Core_Model_Access();
        $area->area = $new_area;


        return $this->save($area);
    }

    public function edit($access_id, array $data)
    {
        $this->checkAcl('edit');

        $access = $this->getGateway()->fetch((int) $access_id);
        if (!$access) {
          return false;
        }

        $access->area = $data['area'];
        return $this->save($access) != false;
    }

    public function fetchMembersWithAccess($accessId)
    {
        return $this->getGateway()->fetchMembersWithAccess($accessId);
    }
    public function fetchbyId($memberAccessId){
        return $this->getGateway()->fetchById($memberAccessId);
    }

    public function removeAccess($accessId, $memberId) {
        return $this->getGateway()->delete($memberId, $accessId);
    }
    /*
    public function fetchMembersWithoutAccess($accessId){
        $membersWithAccess = $this->getGateway()->fetchMembersWithAccess($accessId);
        $allMembers = $this->_memberService->fetchAll();
    }
     */
}
